package com.hongkuncheng.cms.controller.admin;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Controller;
import com.hongkuncheng.cms.controller.BaseController;
import com.hongkuncheng.cms.helper.PageHelper;
import com.hongkuncheng.cms.model.Admin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 账号设置
 *
 * @author 洪坤成
 */
@Controller
@Transactional
@RequestMapping("admin/account")
public class AaccountController extends BaseController {

    // 账号设置
    @RequestMapping
    public String index() {
        Admin admin = (Admin) request.getSession().getAttribute("admin");
        request.setAttribute("admin", admin);
        return view();
    }

    // 账号设置处理
    @RequestMapping("update")
    @ResponseBody
    public void update() {
        Admin admin = (Admin) request.getSession().getAttribute("admin");
        if (!admin.getAccount().equals("admin")) admin.setAccount(request.getParameter("account"));
        admin.setName(request.getParameter("name"));
        admin.setFace(request.getParameter("face"));
        admin.setSex(request.getParameter("sex"));
        admin.setPosition(request.getParameter("position"));
        admin.setMobile(request.getParameter("mobile"));
        admin.setEmail(request.getParameter("email"));
        admin.setWeixinId(request.getParameter("weixinid"));
        admin.setDescription(request.getParameter("description"));
        factorySession.update(admin);
        request.getSession().setAttribute("admin", admin);
        PageHelper.alertAndRedirect("保存成功", "./");
    }

}
